﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SLBehaviourSystem
{
    /// <summary>
    /// 只要有一个节点成功就返回成功
    /// </summary>
    [CompositeNode]
    public class SelectorNode : CompositeNode
    {
        protected override void OnInitData()
        {
            
        }

        protected override void CheckChild()
        {
            childNodes[curIndex].Excute();
        }

        protected override void OnChildNodeComplete()
        {
            childNodeState = childNodes[curIndex].CurNodeState;

            if ( childNodeState == BehaviourNodeState.Success)
            {
                curNodeState = BehaviourNodeState.Success;
            }
            else if (curIndex==childNodes.Count-1 && childNodeState == BehaviourNodeState.Failure)
            {
                curNodeState = BehaviourNodeState.Failure;
            }
            else
            {
                curNodeState = BehaviourNodeState.Running;
            }
            base.OnChildNodeComplete();
        }

        protected override void OnReset()
        {
            base.OnReset();
        }

        protected override bool CheckInterruptState(BehaviourNodeState state)
        {
            return state == BehaviourNodeState.Success || state == BehaviourNodeState.Running;
        }
    }
}
